package com.omt.tarjimdinek.domain.member.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * notifications of member
 * @author chabane
 *
 */
@Entity
@Table(name="a01_ntf")
public class Notification implements Identifiable<Long>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(Notification.class);
    
	/** ID SGBD */
	@Column(name="CNNTF", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
	
	/** content of notification */
    @NotEmpty
	@Column(name="LINTF", nullable=false)
	private String description;
	
	/** category of notification */
    @NotNull
	@JoinColumn(name="CNCTGNTF", nullable=false)
    @ManyToOne
	private CategorieNotification categorie;

    @NotNull
   	@JoinColumn(name="CNMBR", nullable=false)
    @ManyToOne
    private Membre membre;
    
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public CategorieNotification getCategorie() {
		return categorie;
	}

	public void setCategorie(CategorieNotification categorie) {
		this.categorie = categorie;
	}
	
	public Membre getMembre() {
		return membre;
	}

	public void setMembre(Membre membre) {
		this.membre = membre;
	}

	@Transient
	public boolean isIdSet() {
		return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
	
	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getDescription());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("description", getDescription()) //
                .add("categorie", getCategorie()) //
                .add("membre", getMembre()) //
                .add("version", getVersion()) //
                .toString();
    }
}
